//
//  BHCompetitionSignAlertView.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/15.
//

import UIKit

class BHCompetitionSignAlertView: UIView {
    @IBOutlet weak var content_view: UIView!
    
    // 高亮为失败
    @IBOutlet weak var sign_logoImgView: UIImageView!
    // 高亮为失败颜色
    @IBOutlet weak var state_label: UILabel!
    
    @IBOutlet weak var content_label: UILabel!
    
    @IBOutlet weak var confirmBtn: UIButton!
    
    //0 成功  1失败
    var type: Int = 0 {
        didSet {
            self.sign_logoImgView.isHighlighted = type == 1
            self.state_label.isHighlighted = type == 1
        }
    }
    
    var state: String = "签到成功" {
        didSet {
            self.state_label.text = state
        }
    }
    
    var content: String = "" {
        didSet {
            let attri = content.toAttribute().addLineSpace(8)
            attri.addTextAlignmet(.center)
            self.content_label.attributedText = attri
        }
    }
    
    
    
    static func loadFromXib() -> BHCompetitionSignAlertView {
        let viewArray = Bundle.main.loadNibNamed("BHCompetitionSignAlertView", owner: nil, options: nil)
        let view: BHCompetitionSignAlertView = viewArray![0] as! BHCompetitionSignAlertView
        view.frame = CGRect(x: 0, y: 0, width: UIScreen.width, height: UIScreen.height)
        return view
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.isHidden = true
        self.backgroundColor = UIColor.black.withAlphaComponent(0.4)
        self.content_view.addLayerCorner(10, 0, .white)
        self.confirmBtn.addLayerCorner(19, 0, .white)
        
        self.content_view.transform = CGAffineTransform.init(scaleX: 0.01, y: 0.01)
    }
    
    // 关闭
    @IBAction func closeActionCall(_ sender: UIButton) {
        self.isHidden = true
        self.content_view.transform = CGAffineTransform.init(scaleX: 0.01, y: 0.01)
    }
    
    func  show() {
        self.isHidden = false
        UIView.animate(withDuration: 0.25) {
            self.content_view.transform = CGAffineTransform.identity
        }
    }
    
    
}
